const utils=(function(){
    const getStyle = (obj, attr) => {
        if (obj.currentStyle) {
            return obj.currentStyle[attr];
        }
    
        return window.getComputedStyle(obj, null)[attr];
    }
    
    const animate = (oEle, json,callback) => {
        clearInterval(oEle.timer);
        oEle.timer = setInterval(function () {
            let flag =true;
            let current=0;
            let target=0;
            for(let attr in json){
                if(attr==="opacity"){
                    target=parseFloat(json[attr])*100;
                    current = parseFloat(getStyle(oEle, attr))*100;
                }else{
                    target=parseInt(json[attr]);
                    current = parseInt(getStyle(oEle, attr));
                }
            let steps = (target - current) / 10; //有除法,就有小数点
            //把取整后的值,覆盖原来的步长
            steps = steps > 0 ? Math.ceil(steps) : Math.floor(steps);
    
                if(attr==="opacity"){
                    oEle.style[attr] = (current + steps)/100;
                }else if(attr==="zIndex"){
                    oEle.style[attr]=target;
                }
                else{
                    oEle.style[attr] = current + steps + "px";
                }
            if (current!=target) {
                flag=false;
            }
        }
            if(flag){
                clearInterval(oEle.timer)
                if(typeof(callback)==="function"){
                    callback();
                }
            }
        }, 20);
    }
    const getScroll=()=>{
        if(window.pageYOffset!=undefined){
            return{
                left:window.pageXOffset,
                top:window.pageYOffset
            }
        }else if(document.compatMode==='CSS1Compat'){
            return{
                left:document.documentElement.scrollLeft,
                top:document.documentElement.scrollTop
            }
        }
        return{
            left:document.body.scrollLeft,
            top:document.body.scrollTop
        }
    }
    return{
        getStyle,
        animate,
        getScroll
    }
    
})()